package fuzion24.device.vulnerability.vulnerabilities.system;

import android.content.Context;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

import fuzion24.device.vulnerability.util.CPUArch;
import fuzion24.device.vulnerability.vulnerabilities.VulnerabilityTest;

/**
 * Created by fuzion24 on 11/23/15.
 */
public class CVE20151528 implements VulnerabilityTest {

    private final static String TAG = "CVE-2015-1528";

    static {
        System.loadLibrary("cve20151528");
    }

    @Override
    public String getCVEorID() {
        return "CVE-2015-1528";
    }

    private native int doCheck();

    @Override
    public boolean isVulnerable(Context context) throws Exception {
        int checkVal = doCheck();

        if(checkVal == 0) {
            return false;
        }else if(checkVal == 1) {
            return true;
        }else {
            Log.d(TAG, "Got a return value of " + checkVal);
            //TODO: grab more information about failure, errno and error string
            throw new Exception("Error running test");
        }
    }

    @Override
    public List<CPUArch> getSupportedArchitectures() {
        List<CPUArch> supportedArchs = new ArrayList<>();
        supportedArchs.add(CPUArch.ARM);
        supportedArchs.add(CPUArch.ARM7);
        supportedArchs.add(CPUArch.X86);
        return supportedArchs;
    }
}
